{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": "OrderedDict([('a', 2), ('b', 3)])"
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import torch\n",
    "import torch.nn as nn\n",
    "from collections import OrderedDict\n",
    "OrderedDict({\"a\":2,\"b\":3})\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "outputs": [],
   "source": [
    "# LenNet\n",
    "class LeNet(nn.Module):\n",
    "    def __init__(self):\n",
    "        super(LeNet,self).__init__()\n",
    "        self.layer1 = nn.Sequential(OrderedDict({'conv1':nn.Conv2d(1,6,(3,3),padding=1)\n",
    "                       ,'pool1':nn.MaxPool2d(kernel_size=2,stride=2)}))\n",
    "\n",
    "        self.layer2 = nn.Sequential(OrderedDict({'conv2':nn.Conv2d(6,16,(5,5))\n",
    "                       ,'pool2':nn.MaxPool2d(kernel_size=2,stride=2)}))\n",
    "\n",
    "        self.layer3 = nn.Sequential(OrderedDict({'fc1':nn.Linear(400,120)\n",
    "                       ,'fc2':nn.Linear(120,84)\n",
    "                       ,'fc3':nn.Linear(84,10)}))\n",
    "    def forward(self,x):\n",
    "        x=self.layer1(x)\n",
    "        x=self.layel2(x)\n",
    "        x=x.view(x.size(0),-1)\n",
    "        x=self.layer3(x)\n",
    "        return x\n",
    "\n",
    "le_net = LeNet()\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "outputs": [
    {
     "data": {
      "text/plain": "AlexNet(\n  (convs): Sequential(\n    (0): Conv2d(3, 96, kernel_size=(11, 11), stride=(4, 4), padding=(2, 2))\n    (1): ReLU(inplace=True)\n    (2): MaxPool2d(kernel_size=3, stride=2, padding=0, dilation=1, ceil_mode=False)\n    (3): LocalResponseNorm(5, alpha=0.0001, beta=0.75, k=1.0)\n    (4): Conv2d(96, 256, kernel_size=(5, 5), stride=(1, 1), padding=(2, 2), groups=2)\n    (5): ReLU(inplace=True)\n    (6): MaxPool2d(kernel_size=3, stride=2, padding=0, dilation=1, ceil_mode=False)\n    (7): LocalResponseNorm(5, alpha=0.0001, beta=0.75, k=1.0)\n    (8): Conv2d(13, 384, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n    (9): ReLU(inplace=True)\n    (10): Conv2d(384, 384, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n    (11): ReLU(inplace=True)\n    (12): Conv2d(384, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n    (13): ReLU(inplace=True)\n    (14): MaxPool2d(kernel_size=3, stride=2, padding=0, dilation=1, ceil_mode=False)\n  )\n  (fcs): Sequential(\n    (0): Dropout(p=0.5, inplace=False)\n    (1): Linear(in_features=9216, out_features=4096, bias=True)\n    (2): ReLU(inplace=True)\n    (3): Dropout(p=0.5, inplace=False)\n    (4): Linear(in_features=4096, out_features=4096, bias=True)\n    (5): ReLU(inplace=True)\n    (6): Linear(in_features=4096, out_features=100, bias=True)\n  )\n)"
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "class AlexNet(nn.Module):\n",
    "    def __init__(self,num_classes):\n",
    "        super(AlexNet,self).__init__()\n",
    "        self.convs = nn.Sequential(nn.Conv2d(3,96,stride=4,kernel_size=11,padding=2)\n",
    "                                      ,nn.ReLU(inplace=True)\n",
    "                                      ,nn.MaxPool2d(kernel_size=3,stride=2)\n",
    "                                      ,nn.LocalResponseNorm(size=5)\n",
    "\n",
    "                                      ,nn.Conv2d(96,256,padding=2,kernel_size=5,groups=2)\n",
    "                                      ,nn.ReLU(inplace=True)\n",
    "                                      ,nn.MaxPool2d(kernel_size=3,stride=2)\n",
    "                                      ,nn.LocalResponseNorm(size=5)\n",
    "\n",
    "                                      ,nn.Conv2d(13,384,padding=1,kernel_size=3)\n",
    "                                      ,nn.ReLU(inplace=True)\n",
    "\n",
    "                                      ,nn.Conv2d(384,384,padding=1,kernel_size=3)\n",
    "                                      ,nn.ReLU(inplace=True)\n",
    "\n",
    "                                      ,nn.Conv2d(384,256,kernel_size=3,padding=1)\n",
    "                                      ,nn.ReLU(inplace=True)\n",
    "                                      ,nn.MaxPool2d(kernel_size=3,stride=2)\n",
    "                                      )\n",
    "        self.fcs = nn.Sequential(nn.Dropout()\n",
    "                                 ,nn.Linear(6*6*256,4096)\n",
    "                                 ,nn.ReLU(inplace=True)\n",
    "                                 ,nn.Dropout()\n",
    "                                 ,nn.Linear(4096,4096)\n",
    "                                 ,nn.ReLU(inplace=True)\n",
    "                                 ,nn.Linear(4096,num_classes))\n",
    "    def forward(self,x):\n",
    "        x = self.convs(x)\n",
    "        x = x.view(x.size(0),-1)\n",
    "        x = self.fcs(x)\n",
    "        return x\n",
    "\n",
    "AlexNet(100)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "outputs": [
    {
     "data": {
      "text/plain": "VggNet(\n  (features): Sequential(\n    (0): Conv2d(3, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n    (1): ReLU(inplace=True)\n    (2): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n    (3): ReLU(inplace=True)\n    (4): MaxPool2d(kernel_size=2, stride=2, padding=0, dilation=1, ceil_mode=False)\n    (5): Conv2d(64, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n    (6): ReLU(inplace=True)\n    (7): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n    (8): ReLU(inplace=True)\n    (9): MaxPool2d(kernel_size=2, stride=2, padding=0, dilation=1, ceil_mode=False)\n    (10): Conv2d(128, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n    (11): ReLU(inplace=True)\n    (12): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n    (13): ReLU(inplace=True)\n    (14): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n    (15): ReLU(inplace=True)\n    (16): MaxPool2d(kernel_size=2, stride=2, padding=0, dilation=1, ceil_mode=False)\n    (17): Conv2d(256, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n    (18): ReLU(inplace=True)\n    (19): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n    (20): ReLU(inplace=True)\n    (21): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n    (22): ReLU(inplace=True)\n    (23): MaxPool2d(kernel_size=2, stride=2, padding=0, dilation=1, ceil_mode=False)\n    (24): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n    (25): ReLU(inplace=True)\n    (26): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n    (27): ReLU(inplace=True)\n    (28): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n    (29): ReLU(inplace=True)\n    (30): MaxPool2d(kernel_size=2, stride=2, padding=0, dilation=1, ceil_mode=False)\n  )\n  (fcs): Sequential(\n    (0): Linear(in_features=25088, out_features=4096, bias=True)\n    (1): ReLU(inplace=True)\n    (2): Dropout(p=0.5, inplace=False)\n    (3): Linear(in_features=4096, out_features=4096, bias=True)\n    (4): ReLU(inplace=True)\n    (5): Dropout(p=0.5, inplace=False)\n    (6): Linear(in_features=4096, out_features=200, bias=True)\n    (7): ReLU(inplace=True)\n    (8): Softmax(dim=1)\n  )\n)"
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import torch.nn as nn\n",
    "class VggNet(nn.Module):\n",
    "    def __init__(self,num_classes):\n",
    "        super(VggNet,self).__init__()\n",
    "        self.features = nn.Sequential(\n",
    "            nn.Conv2d(3,64,kernel_size=3,padding=1)\n",
    "            ,nn.ReLU(inplace=True)\n",
    "            ,nn.Conv2d(64,64,kernel_size=3,padding=1)\n",
    "            ,nn.ReLU(True)\n",
    "\n",
    "            ,nn.MaxPool2d(kernel_size=2,stride=2)\n",
    "            ,nn.Conv2d(64,128,kernel_size=3,padding=1)\n",
    "            ,nn.ReLU(True)\n",
    "            ,nn.Conv2d(128,128,kernel_size=3,padding=1)\n",
    "            ,nn.ReLU(True)\n",
    "            ,nn.MaxPool2d(kernel_size=2,stride=2)\n",
    "\n",
    "            ,nn.Conv2d(128,256,kernel_size=3,padding=1)\n",
    "            ,nn.ReLU(True)\n",
    "            ,nn.Conv2d(256,256,kernel_size=3,padding=1)\n",
    "            ,nn.ReLU(True)\n",
    "            ,nn.Conv2d(256,256,kernel_size=3,padding=1)\n",
    "            ,nn.ReLU(True)\n",
    "            ,nn.MaxPool2d(kernel_size=2,stride=2)\n",
    "\n",
    "            ,nn.Conv2d(256,512,kernel_size=3,padding=1)\n",
    "            ,nn.ReLU(True)\n",
    "            ,nn.Conv2d(512,512,kernel_size=3,padding=1)\n",
    "            ,nn.ReLU(True)\n",
    "            ,nn.Conv2d(512,512,kernel_size=3,padding=1)\n",
    "            ,nn.ReLU(True)\n",
    "            ,nn.MaxPool2d(kernel_size=2,stride=2)\n",
    "\n",
    "            ,nn.Conv2d(512,512,kernel_size=3,padding=1)\n",
    "            ,nn.ReLU(True)\n",
    "            ,nn.Conv2d(512,512,kernel_size=3,padding=1)\n",
    "            ,nn.ReLU(True)\n",
    "            ,nn.Conv2d(512,512,kernel_size=3,padding=1)\n",
    "            ,nn.ReLU(True)\n",
    "            ,nn.MaxPool2d(kernel_size=2,stride=2)\n",
    "        )\n",
    "        self.fcs = nn.Sequential(\n",
    "            nn.Linear(512*7*7,4096)\n",
    "            ,nn.ReLU(True)\n",
    "            ,nn.Dropout()\n",
    "            ,nn.Linear(4096,4096)\n",
    "            ,nn.ReLU(True)\n",
    "            ,nn.Dropout()\n",
    "            ,nn.Linear(4096,num_classes)\n",
    "            ,nn.ReLU(True)\n",
    "            ,nn.Softmax(dim=1)\n",
    "\n",
    "        )\n",
    "    def forward(self,x):\n",
    "        x = self.features(x)\n",
    "        x = x.view(x.size(0),-1)\n",
    "        x = self.fcs(x)\n",
    "        return x\n",
    "\n",
    "VggNet(200)\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "name": "conda-env-DL-py",
   "language": "python",
   "display_name": "Python [conda env:DL] *"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}